package com.shambles.manage2.service.impl;

import cn.hutool.core.util.IdUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shambles.manage2.service.QuarantineStuffService;
import com.shambles.manage2.service.SysUserService;
import com.shambles.manage2.tkmapper.entity.AbattoirBooth;
import com.shambles.manage2.tkmapper.entity.MessageRequestVM;
import com.shambles.manage2.tkmapper.entity.QuarantineStuff;
import com.shambles.manage2.tkmapper.entity.SysUser;
import com.shambles.manage2.tkmapper.mapper.QuarantineStuffMapper;
import com.shambles.manage2.tkmapper.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.weekend.Weekend;

/**
 * @author yangsy
 * @description
 * @date 2020/03/01
 */
@Service
public class QuarantineStuffServiceImpl implements QuarantineStuffService {

    @Autowired
    private QuarantineStuffMapper quarantineStuffMapper;

    /**
     * 查询材料
     * @param messageRequestVM
     * @return
     */
    @Override
    public PageInfo<QuarantineStuff> querQuarantineStuffAll(MessageRequestVM messageRequestVM) {
        return PageHelper.startPage(messageRequestVM.getPageIndex(), messageRequestVM.getPageSize()).doSelectPageInfo(() ->
                quarantineStuffMapper.querQuarantineStuffAll()
        );
    }

    /**
     * 删除材料
     * @param guid
     */
    @Override
    public void deleteQuarantineStuff(String guid) {
        this.quarantineStuffMapper.deleteQuarantineStuff(guid);

    }

    /**
     * 修改材料
     * @param quarantineStuff
     */
    @Override
    public void updateQuarantineStuff(QuarantineStuff quarantineStuff) {
        String Guid = quarantineStuff.getGuid();
        Weekend<QuarantineStuff> quarantineStuffWeekend = new Weekend<>(QuarantineStuff.class);
        quarantineStuffWeekend.weekendCriteria().andEqualTo(QuarantineStuff::getGuid, Guid);
        this.quarantineStuffMapper.updateByExampleSelective(quarantineStuff, quarantineStuffWeekend);

    }

    /**
     * 添加材料
     * @param quarantineStuff
     */
    @Override
    public void insertQuarantineStuff(QuarantineStuff quarantineStuff) {
        QuarantineStuff insertQuarantineStuff=new QuarantineStuff();
        insertQuarantineStuff.setGuid(IdUtil.simpleUUID());
        insertQuarantineStuff.setMerchantGuid(quarantineStuff.getMerchantGuid());
        insertQuarantineStuff.setSubscribeGuid(quarantineStuff.getSubscribeGuid());
        insertQuarantineStuff.setType(quarantineStuff.getType());
        insertQuarantineStuff.setAddress(quarantineStuff.getAddress());
        insertQuarantineStuff.setTime(quarantineStuff.getTime());
        this.quarantineStuffMapper.insertSelective(insertQuarantineStuff);
    }
}
